#!/usr/bin/python
import subprocess
import os
import sys
def cmd(command):
    p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    sts = os.waitpid(p.pid, 0)[1]
    ret = p.stdout.read()
    return (sts, ret)

def sshCmd(host, user, command):
    newcmd = 'ssh -l %s %s %s' % (user, host, command)
    return cmd(newcmd)

def revCmd(host, src, dest, user='root'):
    newcmd = 'scp %s@%s:%s %s' % (user, host, dest, src)
    return cmd(newcmd)

def scpCmd(host, src, dest, user='root'):
    newcmd = 'scp %s %s@%s:%s' % (src, user, host, dest)
    return cmd(newcmd)

